﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// 宝箱武器点击效果
/// </summary>
public class WeaponIconBag : MonoBehaviour {

    private string grade;//武器的等级
    public WeaponInfo weaponInfo; //武器对象

    //武器icon被点击的时候
    public void OnClick()
    {
        //把上一个被选中的武器设置回未选中状态
        if (TreasureBoxManager._instance.tempGo != null)
        {
            TreasureBoxManager._instance.tempGo.GetComponent<Image>().sprite = Resources.Load("Warehouse/weaponBox", typeof(Sprite)) as Sprite;
        }
        //获取武器等级
        grade =  gameObject.transform.Find("grade").GetComponent<Text>().text;
        //设置选中效果
        SelectEffect(grade);
        //记录当前选中的武器，当点击下一个武器的时候此对象则是 上一个
        TreasureBoxManager._instance.tempGo = gameObject;
    }
    //根据等级设置选中效果
    void SelectEffect(string grade)
    {
        string name = "";
        if (string.Equals(grade, "S"))
        {
            name = "selectS";
        }else if (string.Equals(grade, "A"))
        {
            name = "selectA";
        }
        else if (string.Equals(grade, "B"))
        {
            name = "selectB";
        }
        else if (string.Equals(grade, "C"))
        {
            name = "selectC";
        }
        else if (string.Equals(grade, "D"))
        {
            name = "selectD";
        }
        gameObject.GetComponent<Image>().sprite = Resources.Load("Warehouse/"+name, typeof(Sprite)) as Sprite;
    }
}
